-- hp_trans_building
-- created by huanghr
-- 血量低于百分比转换成建筑

return {
    -- 返回的是提升的攻击点数
    apply = function(prop, baseValue)
        return prop[3];
    end,

    trigger = function(who, prop)
        local rate = math.modf(1000 * who:queryAttrib("hp") / who:queryAttrib("max_hp"));
        local value = tonumber(prop[2]);

        if rate >= value then
             return;
        end

        local classId = who:getClassId();

        local buildingId = prop[3];
        local pos = who:getOwner();
        local grid = DungeonM.getGridByPos(pos);

        -- 标记死亡
        who.dbase:set("is_dead", 1);

        -- 尝试清怪处理
        DungeonServiceM.monsterClear();

        -- 将格子设置为无效
        grid:changeState(GRID_STATE_DISABLE);

        EventMgr.fire(event.MONSTER_TRANS_BUILDING, {["pos"] = pos, });

        local para = {["class"] = buildingId, ["element"] = 30606};

        local class = para.class;
        -- 建筑装换
        local grid = DungeonM.transformGrid(class, pos, GRID_STATE_OPEN, para)
    end,

    record = function(target, prop, path)
        return false;
    end
};